package com.pj.point.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.pj.point.R;
import com.pj.point.litepal.CreateData;

import java.util.List;

public class CreateListAdapter extends MyAdapter {

    List<CreateData> data;
    Context context;

    public CreateListAdapter(List<CreateData> data, Context context) {
        super(data);
        this.data = data;
        this.context = context;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        CreateData createData = data.get(i);
        switch (createData.getKey()){
            case "image":{
                View v = LayoutInflater.from(context).inflate(R.layout.image_item, null);
                ImageView imageView = v.findViewById(R.id.image_item_img);
                Toast.makeText(context, imageView.toString(), Toast.LENGTH_SHORT).show();
                Glide.with(context).load(createData.getValue()).into(imageView);
                return v;
            }
            case "text":{
                EditText v = new EditText(context);
                v.setLayoutParams(new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
                v.setText(createData.getValue());
                v.setTextSize(20);
                v.setBackground(null);
                return v;
            }
        }
        return null;
    }
}
